package faf.web.data;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class AuthentificationFormValidator implements Validator {

	@SuppressWarnings("rawtypes")
	@Override
	public boolean supports(Class arg0) {
		return AuthentificationForm.class.equals(arg0);
	}

	@Override
	public void validate(Object command, Errors errors) {
		if(command == null) {
			errors.rejectValue("email", "value-required");
			return;
		}
		
		AuthentificationForm form = (AuthentificationForm) command;
		if(form.getEmail().length() == 0) {
			errors.rejectValue("email", "value-required");
		}
		if(form.getPassword().length() == 0) {
			errors.rejectValue("password", "value-required");
		}
	}

}
